/*
 * server
 */

'use strict';

const path    = require('path')
const koa     = require('koa')
const logger  = require('koa-logger')
const router  = require('koa-router')
const json    = require('koa-json')
const render  = require('koa-views')
const serve   = require('koa-static')
const cors    = require('kcors')
const etag    = require('koa-etag');
const conditional = require('koa-conditional-get');
const gzip    = require('koa-gzip');

const app = koa()

const routesInstance = require('./router/index')

// middleware
app.use(logger())
app.use(cors({
  origin: '*'
}))
app.use(gzip());
app.use(conditional());
app.use(etag());
app.use(json());

// serve files from ./dist
app.use(serve(path.join(__dirname, '../dist')))
   .use(render(path.join(__dirname, './'), {
        map: {
           html: 'ejs'
        }
   }))
   .use(router(app))

routesInstance(app)

module.exports = app
